package org.ohuang

import java.io.File



/**
 * 合并value文件的xml
 * isNewID ture保留原框架id
 * isXmlNew  xml是否使用新的值
 */
fun mergeValueXml(path: String, path2: String,isNewID: Boolean=false,isXmlNew:Boolean=false){
    var file = File(path)

    file.listFiles()?.forEach {
        if (!it.name.equals("public.xml")) {
            var file1 = File(path2 + "/${it.name}")
            if (file1.exists()) {
                mergeXml(it.absolutePath, file1.absolutePath)
                if (isXmlNew){
                    xmlRemoveIdenticalElementDeleteFront(file1.absolutePath)
                }else {
                    xmlRemoveIdenticalElement(file1.absolutePath)
                }
            } else {
                it.copyTo(file1)
            }
        }else{
            var file1 = File(path2 + "/${it.name}")
            if (file1.exists()) {
                if (isNewID){
                    mergePublicXmlWewId(it.absolutePath, file1.absolutePath)
                }else {
                    mergePublicXml(it.absolutePath, file1.absolutePath)
                }
            } else {
                it.copyTo(file1)
            }

        }

    }
}

/**
 * 删除xml重复项
 */
fun valueRemoveIdenticalNoPublic(path: String) {
    var file = File(path)
    if (file.isFile) {
        xmlRemoveIdenticalElement(path)
    } else {
        file.listFiles()?.forEach {
            if (!it.name.equals("public.xml")) {
                xmlRemoveIdenticalElement(it.absolutePath)
            }
        }
    }
}